#include "LcData.h"

#include <float.h>
#include <limits.h>

#include "ComDefine.h"

bool CLcData::IsCommNormal()
{
    return (0 == m_uCommState);
}

bool CLcData::IsCommFault()
{
    return (1 == m_uCommState);
}

bool CLcData::IsRunning()
{
    return (0 == m_uRunState);
}

bool CLcData::IsStopped()
{
    return (1 == m_uRunState);
}

bool CLcData::IsFault()
{
    return (1 == m_uFaultState);
}

bool CLcData::IsNoFault()
{
    return (0 == m_uFaultState);
}

bool CLcData::IsAlarm()
{
    return (1 == m_uAlarmState);
}

bool CLcData::IsNoAlarm()
{
    return (0 == m_uAlarmState);
}

bool CLcData::IsOpening()
{
    return (1 == m_uSwitchState);
}

bool CLcData::IsClosed()
{
    return (0 == m_uSwitchState);
}

//获取***的显示文本
QString CLcData::GetCommStateText()
{
    if (0xFFFF == m_uCommState)
    {
        return QObject::tr("---");
    }
    else if (1 == m_uCommState)
    {
        return QObject::tr("故障");
    }
    else
    {
        return QObject::tr("正常");
    }
}

void CLcData::InitToInvalid()
{
    m_uCommState = 0xFFFF;
    for (int i = 0; i < ARRAYSIZE(m_uRev); ++i)
    {
        m_uRev[i] = 0xFFFF;
    }
    for (int i = 0; i < ARRAYSIZE(m_fRev); ++i)
    {
        m_fRev[i] = FLT_MAX;
    }

    //转发的100个UINT16数据
    m_uRunState = 0xFFFF;
    m_uFaultState = 0xFFFF;
    m_uAlarmState = 0xFFFF;
    m_uSwitchState = 0xFFFF;
    m_uWorkState = 0xFFFF;

    m_uFaultCode = 0xFFFF;
    m_uEngineSpeed = 0xFFFF;
    m_uPumpSpeed = 0xFFFF;
    m_uDebugState = 0xFFFF;
    m_uAlarmCode1 = 0xFFFF;

    m_uAlarmCode2 = 0xFFFF;
    m_uAlarmCode3 = 0xFFFF;
    m_uAlarmCode4 = 0xFFFF;
    m_uAlarmCode5 = 0xFFFF;
    m_uAlarmCode6 = 0xFFFF;

    m_uFaultCode1 = 0xFFFF;
    m_uFaultCode2 = 0xFFFF;
    m_uFaultCode3 = 0xFFFF;
    m_uFaultCode4 = 0xFFFF;
    m_uFaultCode5 = 0xFFFF;

    m_uFaultCode6 = 0xFFFF;

    m_uPumpState1 = 0xFFFF;
    m_uPumpState2 = 0xFFFF;
    m_uPumpState3 = 0xFFFF;
    m_uPumpState4 = 0xFFFF;
    m_uPumpState5 = 0xFFFF;

    m_uCoolerState1 = 0xFFFF;
    m_uCoolerState2 = 0xFFFF;
    m_uCoolerState3 = 0xFFFF;
    m_uCoolerState4 = 0xFFFF;
    m_uCoolerState5 = 0xFFFF;

    m_uSupplyWaterState = 0xFFFF;
    m_uRemoteState = 0xFFFF;
    m_uAlarmLevel = 0xFFFF;
    m_uMachineEnable = 0xFFFF;
    m_uTempControlMode = 0xFFFF;
    for (int i = 0; i < ARRAYSIZE(m_uData); ++i)
    {
        m_uData[i] = 0xFFFF;
    }

    //转发的100个FLOAT数据
    m_fOutWaterTemp = FLT_MAX;
    m_fInWaterTemp = FLT_MAX;
    m_fOutWaterPres = FLT_MAX;
    m_fInWaterPres = FLT_MAX;
    m_fEnvTemp = FLT_MAX;

    m_fCoolStartTemp = FLT_MAX;
    m_fCoolStopTemp = FLT_MAX;
    m_fCoolDiffTemp = FLT_MAX;
    m_fHeatStartTemp = FLT_MAX;
    m_fHeatStopTemp = FLT_MAX;

    m_fHeatDiffTemp = FLT_MAX;
    m_fDryStartHumi = FLT_MAX;
    m_fDryStopHumi = FLT_MAX;
    m_fDryDiffHumi = FLT_MAX;
    m_fDebugSglMaxTemp = FLT_MAX;

    m_fDebugSglMinTemp = FLT_MAX;
    m_fDebugSglAvgTemp = FLT_MAX;
    m_fDebugSglMaxTempDiff = FLT_MAX;
    m_fVentilateTemp = FLT_MAX;
    m_fAcCur = FLT_MAX;

    m_fAcVol = FLT_MAX;
    m_fDcCur = FLT_MAX;
    m_fDcVol = FLT_MAX;
    m_fCoolFlow = FLT_MAX;
    m_fOutSteamTemp = FLT_MAX;

    m_fInSteamTemp = FLT_MAX;

    for (int i = 0; i < ARRAYSIZE(m_fData); ++i)
    {
        m_fData[i] = FLT_MAX;
    }

    m_uSetWorkState = 0xFFFF;
    m_uSetWorkStateCopy = 0xFFFF;
    m_fSetCoolStartTemp = FLT_MAX;
    m_fSetCoolStartTempCopy = FLT_MAX;
    m_fSetCoolStopTemp = FLT_MAX;
    m_fSetCoolStopTempCopy = FLT_MAX;
    m_fSetCoolDiffTemp = FLT_MAX;
    m_fSetCoolDiffTempCopy = FLT_MAX;
    m_fSetHeatStartTemp = FLT_MAX;
    m_fSetHeatStartTempCopy = FLT_MAX;
    m_fSetHeatStopTemp = FLT_MAX;
    m_fSetHeatStopTempCopy = FLT_MAX;
    m_fSetHeatDiffTemp = FLT_MAX;
    m_fSetHeatDiffTempCopy = FLT_MAX;
    m_fSetDryStartHumi = FLT_MAX;
    m_fSetDryStartHumiCopy = FLT_MAX;
    m_fSetDryStopHumi = FLT_MAX;
    m_fSetDryStopHumiCopy = FLT_MAX;
    m_fSetDryDiffHumi = FLT_MAX;
    m_fSetDryDiffHumiCopy = FLT_MAX;
    m_fSetTargetTemp = FLT_MAX;
    m_fSetTargetTempCopy = FLT_MAX;
    m_fSetTargetCheckTemp = FLT_MAX;
    m_fSetTargetCheckTempCopy = FLT_MAX;

    m_uSetSwitch = 0xFFFF;
    m_uSetSwitchCopy = 0xFFFF;
    m_uSetControlMode = 0xFFFF;
    m_uSetControlModeCopy = 0xFFFF;
    m_uSetMachineEnable = 0xFFFF;
    m_uSetMachineEnableCopy = 0xFFFF;
    m_uSetTempControlMode = 0xFFFF;
    m_uSetTempControlModeCopy = 0xFFFF;
    m_fSetMonitorTempMax = FLT_MAX;
    m_fSetMonitorTempMaxCopy = FLT_MAX;
    m_fSetMonitorTempMin = FLT_MAX;
    m_fSetMonitorTempMinCopy = FLT_MAX;
    m_fSetMonitorMaxAvg = FLT_MAX;
    m_fSetMonitorMaxAvgCopy = FLT_MAX;

    for (int i = 0; i < ARRAYSIZE(m_uSetData); ++i)
    {
        m_uSetData[i] = 0xFFFF;
    }

    for (int i = 0; i < ARRAYSIZE(m_uSetDataCopy); ++i)
    {
        m_uSetDataCopy[i] = 0xFFFF;
    }
}

void CLcData::InitToZero()
{
    m_uCommState = 0;
    for (int i = 0; i < ARRAYSIZE(m_uRev); ++i)
    {
        m_uRev[i] = 0;
    }
    for (int i = 0; i < ARRAYSIZE(m_fRev); ++i)
    {
        m_fRev[i] = 0.0;
    }

    //转发的100个UINT16数据
    m_uRunState = 0;
    m_uFaultState = 0;
    m_uAlarmState = 0;
    m_uSwitchState = 0;
    m_uWorkState = 0;

    m_uFaultCode = 0;
    m_uEngineSpeed = 0;
    m_uPumpSpeed = 0;
    m_uDebugState = 0;
    m_uAlarmCode1 = 0;

    m_uAlarmCode2 = 0;
    m_uAlarmCode3 = 0;
    m_uAlarmCode4 = 0;
    m_uAlarmCode5 = 0;
    m_uAlarmCode6 = 0;

    m_uFaultCode1 = 0;
    m_uFaultCode2 = 0;
    m_uFaultCode3 = 0;
    m_uFaultCode4 = 0;
    m_uFaultCode5 = 0;

    m_uFaultCode6 = 0;
    m_uPumpState1 = 0;
    m_uPumpState2 = 0;
    m_uPumpState3 = 0;
    m_uPumpState4 = 0;
    m_uPumpState5 = 0;

    m_uCoolerState1 = 0;
    m_uCoolerState2 = 0;
    m_uCoolerState3 = 0;
    m_uCoolerState4 = 0;
    m_uCoolerState5 = 0;

    m_uSupplyWaterState = 0;
    m_uRemoteState = 0;
    m_uAlarmLevel = 0;
    m_uMachineEnable = 0;
    m_uTempControlMode = 0;
    for (int i = 0; i < ARRAYSIZE(m_uData); ++i)
    {
        m_uData[i] = 0;
    }

    //转发的100个FLOAT数据
    m_fOutWaterTemp = 0.0;
    m_fInWaterTemp = 0.0;
    m_fOutWaterPres = 0.0;
    m_fInWaterPres = 0.0;
    m_fEnvTemp = 0.0;

    m_fCoolStartTemp = 0.0;
    m_fCoolStopTemp = 0.0;
    m_fCoolDiffTemp = 0.0;
    m_fHeatStartTemp = 0.0;
    m_fHeatStopTemp = 0.0;

    m_fHeatDiffTemp = 0.0;
    m_fDryStartHumi = 0.0;
    m_fDryStopHumi = 0.0;
    m_fDryDiffHumi = 0.0;
    m_fDebugSglMaxTemp = 0.0;

    m_fDebugSglMinTemp = 0.0;
    m_fDebugSglAvgTemp = 0.0;
    m_fDebugSglMaxTempDiff = 0.0;
    m_fVentilateTemp = 0.0;
    m_fAcCur = 0.0;

    m_fAcVol = 0.0;
    m_fDcCur = 0.0;
    m_fDcVol = 0.0;
    m_fCoolFlow = 0.0;
    m_fOutSteamTemp = 0.0;

    m_fInSteamTemp = 0.0;
    for (int i = 0; i < ARRAYSIZE(m_fData); ++i)
    {
        m_fData[i] = 0.0;
    }

    m_uSetWorkState = 0;
    m_uSetWorkStateCopy = 0;
    m_fSetCoolStartTemp = 0.0;
    m_fSetCoolStartTempCopy = 0.0;
    m_fSetCoolStopTemp = 0.0;
    m_fSetCoolStopTempCopy = 0.0;
    m_fSetCoolDiffTemp = 0.0;
    m_fSetCoolDiffTempCopy = 0.0;
    m_fSetHeatStartTemp = 0.0;
    m_fSetHeatStartTempCopy = 0.0;
    m_fSetHeatStopTemp = 0.0;
    m_fSetHeatStopTempCopy = 0.0;
    m_fSetHeatDiffTemp = 0.0;
    m_fSetHeatDiffTempCopy = 0.0;
    m_fSetDryStartHumi = 0.0;
    m_fSetDryStartHumiCopy = 0.0;
    m_fSetDryStopHumi = 0.0;
    m_fSetDryStopHumiCopy = 0.0;
    m_fSetDryDiffHumi = 0.0;
    m_fSetDryDiffHumiCopy = 0.0;
    m_fSetTargetTemp = 0.0;
    m_fSetTargetTempCopy = 0.0;
    m_fSetTargetCheckTemp = 0.0;
    m_fSetTargetCheckTempCopy = 0.0;

    m_uSetSwitch = 0;
    m_uSetSwitchCopy = 0;
    m_uSetControlMode = 0;
    m_uSetControlModeCopy = 0;
    m_uSetMachineEnable = 0;
    m_uSetMachineEnableCopy = 0;
    m_uSetTempControlMode = 0;
    m_uSetTempControlModeCopy = 0;
    m_fSetMonitorTempMax = 0.0;
    m_fSetMonitorTempMaxCopy = 0.0;
    m_fSetMonitorTempMin = 0.0;
    m_fSetMonitorTempMinCopy = 0.0;
    m_fSetMonitorMaxAvg = 0.0;
    m_fSetMonitorMaxAvgCopy = 0.0;

    for (int i = 0; i < ARRAYSIZE(m_uSetData); ++i)
    {
        m_uSetData[i] = 0;
    }

    for (int i = 0; i < ARRAYSIZE(m_uSetDataCopy); ++i)
    {
        m_uSetDataCopy[i] = 0;
    }
}

void CLcData::InitToValue(quint16 uvalue, float fvalue)
{
    m_uCommState = uvalue;
    for (int i = 0; i < ARRAYSIZE(m_uRev); ++i)
    {
        m_uRev[i] = uvalue;
    }
    for (int i = 0; i < ARRAYSIZE(m_fRev); ++i)
    {
        m_fRev[i] = fvalue;
    }

    //转发的100个UINT16数据
    m_uRunState = uvalue;
    m_uFaultState = uvalue;
    m_uAlarmState = uvalue;
    m_uSwitchState = uvalue;
    m_uWorkState = uvalue;

    m_uFaultCode = uvalue;
    m_uEngineSpeed = uvalue;
    m_uPumpSpeed = uvalue;
    m_uDebugState = uvalue;
    m_uAlarmCode1 = uvalue;

    m_uAlarmCode2 = uvalue;
    m_uAlarmCode3 = uvalue;
    m_uAlarmCode4 = uvalue;
    m_uAlarmCode5 = uvalue;
    m_uAlarmCode6 = uvalue;

    m_uFaultCode1 = uvalue;
    m_uFaultCode2 = uvalue;
    m_uFaultCode3 = uvalue;
    m_uFaultCode4 = uvalue;
    m_uFaultCode5 = uvalue;

    m_uFaultCode6 = uvalue;
    m_uPumpState1 = uvalue;
    m_uPumpState2 = uvalue;
    m_uPumpState3 = uvalue;
    m_uPumpState4 = uvalue;
    m_uPumpState5 = uvalue;

    m_uCoolerState1 = uvalue;
    m_uCoolerState2 = uvalue;
    m_uCoolerState3 = uvalue;
    m_uCoolerState4 = uvalue;
    m_uCoolerState5 = uvalue;

    m_uSupplyWaterState = uvalue;
    m_uRemoteState = uvalue;
    m_uAlarmLevel = uvalue;
    m_uMachineEnable = uvalue;
    m_uTempControlMode = uvalue;
    for (int i = 0; i < ARRAYSIZE(m_uData); ++i)
    {
        m_uData[i] = uvalue;
    }

    //转发的100个FLOAT数据
    m_fOutWaterTemp = fvalue;
    m_fInWaterTemp = fvalue;
    m_fOutWaterPres = fvalue;
    m_fInWaterPres = fvalue;
    m_fEnvTemp = fvalue;

    m_fCoolStartTemp = fvalue;
    m_fCoolStopTemp = fvalue;
    m_fCoolDiffTemp = fvalue;
    m_fHeatStartTemp = fvalue;
    m_fHeatStopTemp = fvalue;

    m_fHeatDiffTemp = fvalue;
    m_fDryStartHumi = fvalue;
    m_fDryStopHumi = fvalue;
    m_fDryDiffHumi = fvalue;
    m_fDebugSglMaxTemp = fvalue;

    m_fDebugSglMinTemp = fvalue;
    m_fDebugSglAvgTemp = fvalue;
    m_fDebugSglMaxTempDiff = fvalue;
    m_fVentilateTemp = fvalue;
    m_fAcCur = fvalue;

    m_fAcVol = fvalue;
    m_fDcCur = fvalue;
    m_fDcVol = fvalue;
    m_fCoolFlow = fvalue;
    m_fOutSteamTemp = fvalue;

    m_fInSteamTemp = fvalue;
    for (int i = 0; i < ARRAYSIZE(m_fData); ++i)
    {
        m_fData[i] = fvalue;
    }

    m_uSetWorkState = uvalue;
    m_uSetWorkStateCopy = uvalue;
    m_fSetCoolStartTemp = fvalue;
    m_fSetCoolStartTempCopy = fvalue;
    m_fSetCoolStopTemp = fvalue;
    m_fSetCoolStopTempCopy = fvalue;
    m_fSetCoolDiffTemp = fvalue;
    m_fSetCoolDiffTempCopy = fvalue;
    m_fSetHeatStartTemp = fvalue;
    m_fSetHeatStartTempCopy = fvalue;
    m_fSetHeatStopTemp = fvalue;
    m_fSetHeatStopTempCopy = fvalue;
    m_fSetHeatDiffTemp = fvalue;
    m_fSetHeatDiffTempCopy = fvalue;
    m_fSetDryStartHumi = fvalue;
    m_fSetDryStartHumiCopy = fvalue;
    m_fSetDryStopHumi = fvalue;
    m_fSetDryStopHumiCopy = fvalue;
    m_fSetDryDiffHumi = fvalue;
    m_fSetDryDiffHumiCopy = fvalue;
    m_fSetTargetTemp = fvalue;
    m_fSetTargetTempCopy = fvalue;
    m_fSetTargetCheckTemp = fvalue;
    m_fSetTargetCheckTempCopy = fvalue;

    m_uSetSwitch = uvalue;
    m_uSetSwitchCopy = uvalue;
    m_uSetControlMode = uvalue;
    m_uSetControlModeCopy = uvalue;
    m_uSetMachineEnable = uvalue;
    m_uSetMachineEnableCopy = uvalue;
    m_uSetTempControlMode = uvalue;
    m_uSetTempControlModeCopy = uvalue;
    m_fSetMonitorTempMax = fvalue;
    m_fSetMonitorTempMaxCopy = fvalue;
    m_fSetMonitorTempMin = fvalue;
    m_fSetMonitorTempMinCopy = fvalue;
    m_fSetMonitorMaxAvg = fvalue;
    m_fSetMonitorMaxAvgCopy = fvalue;

    for (int i = 0; i < ARRAYSIZE(m_uSetData); ++i)
    {
        m_uSetData[i] = uvalue;
    }

    for (int i = 0; i < ARRAYSIZE(m_uSetDataCopy); ++i)
    {
        m_uSetDataCopy[i] = uvalue;
    }
}
